'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFYhbhCtrl
 * @description
 * # FinanceFYhbhCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFYhbhCtrl', function($scope, openApi, Util, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
            // 底部关联模块类型选框添加
        $scope.getAccountTypeList = function () {
            var param = {};
            param.type = "银行保函类型";
            Util.getKeyValue(param, function (data) {
                $scope.accountTypeList=data.data;
            })
        };

        $scope.submit = function(operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.bankGuarantee;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function() {
            if (!$scope.param.validityDate) {
                Util.Toast("请选择预计有效期至");
                return;
            }
            if (!$scope.param.guaranteeType) {
                Util.Toast("请选择保函类型");
                return;
            }
            if (!$scope.param.amount) {
                if ($scope.param.amount !== 0) {
                    Util.Toast("请填写保函开具金额");
                    return;
                }
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData(id, function(data) {
                $scope.param = data;
            });
            $scope.getAccountTypeList()
        };
        // 初始化
        init();
    });